﻿Imports BE.BE
Imports DAL.DAL

Namespace BL
    Public Class Persona_BL

        Shared Sub altaPersona(pPersona As Persona_BE)

            Try
                DAL_Persona.altaPersona(pPersona)
                If pPersona.Telefonos.Count > 0 Then
                    For Each telefono As Telefono_BE In pPersona.Telefonos

                        telefono.TipoObjeto = Telefono_BE.EnumTipoObjeto.Persona
                        telefono.IdObjeto = pPersona.Id
                        Telefono_BL.guardarTelefono(telefono)

                    Next
                End If
            Catch ex As Exception
                Throw ex
            End Try
           
        End Sub

        Shared Sub bajaPersona(pPersona As Persona_BE)
            Try
                DAL_Persona.bajaPersona(pPersona)
            Catch ex As Exception
                Throw ex
            End Try

        End Sub

        Shared Sub modificarPersona(pPersona As Persona_BE)
            Try
                DAL_Persona.modificarPersona(pPersona)
            Catch ex As Exception
                Throw ex
            End Try

        End Sub


        Shared Function traerPersona(pPersona As Persona_BE) As Persona_BE
            Dim mPersona As New Persona_BE
            Try
                DAL_Persona.traerPersona(pPersona)
            Catch ex As Exception
                Throw ex
            End Try

            Return mPersona
        End Function

        Shared Function listarPersonas() As List(Of Persona_BE)
            Try
                Return DAL_Persona.listarPersona()
            Catch ex As Exception
                Throw ex
            End Try

        End Function


        Shared Sub altaTelefono(pPersona As Persona_BE, pTelefono As Telefono_BE)
            pPersona.Telefonos.Add(pTelefono)
        End Sub

        Shared Sub bajaTelefono(pPersona As Persona_BE, pTelefono As Telefono_BE)

            For i As Integer = pPersona.Telefonos.Count - 1 To 0

                If pPersona.Telefonos.Item(i).Numero = pTelefono.Numero Then

                    pPersona.Telefonos.RemoveAt(i)

                End If

            Next

        End Sub

        Shared Sub modificarTelefono(pTelefono As Telefono_BE)

        End Sub

    End Class
End Namespace


